#Boa:Dialog:Dialog1

import wx
import ClientEnemyBattlefieldDlg

def create(parent, app ):
    return Dialog1(parent, app )

[wxID_DIALOG1, wxID_DIALOG1BUTTONATTACKPLAYER, wxID_DIALOG1BUTTONREFRESH, 
 wxID_DIALOG1BUTTONSENDMESSAGE, wxID_DIALOG1BUTTONSENDMESSAGEENEMY, 
 wxID_DIALOG1BUTTONSHOWPLAYERBATTLEFIELD, wxID_DIALOG1LISTBOXENEMIES, 
 wxID_DIALOG1LISTBOXPLAYERSINGAME, wxID_DIALOG1STATICBOX1, 
 wxID_DIALOG1STATICBOX2, 
] = [wx.NewId() for _init_ctrls in range(10)]

class Dialog1(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DIALOG1, name=u'Dialog1', parent=prnt,
              pos=wx.Point(380, 126), size=wx.Size(264, 463),
              style=wx.DEFAULT_DIALOG_STYLE, title=u'Players')
        self.SetClientSize(wx.Size(256, 436))
        self.Center(wx.BOTH)
        self.Bind(wx.EVT_ACTIVATE, self.OnDialog1Activate)
        self.Bind(wx.EVT_INIT_DIALOG, self.OnDialog1InitDialog)

        self.staticBox1 = wx.StaticBox(id=wxID_DIALOG1STATICBOX1,
              label=u'Enemies', name='staticBox1', parent=self, pos=wx.Point(8,
              0), size=wx.Size(240, 224), style=0)

        self.listBoxEnemies = wx.ListBox(choices=[],
              id=wxID_DIALOG1LISTBOXENEMIES, name=u'listBoxEnemies',
              parent=self, pos=wx.Point(16, 16), size=wx.Size(224, 168),
              style=0)

        self.buttonShowPlayerBattlefield = wx.Button(id=wxID_DIALOG1BUTTONSHOWPLAYERBATTLEFIELD,
              label=u'Show player battlefield',
              name=u'buttonShowPlayerBattlefield', parent=self,
              pos=wx.Point(114, 192), size=wx.Size(125, 23), style=0)
        self.buttonShowPlayerBattlefield.Bind(wx.EVT_BUTTON,
              self.OnButtonShowPlayerBattlefieldButton,
              id=wxID_DIALOG1BUTTONSHOWPLAYERBATTLEFIELD)

        self.staticBox2 = wx.StaticBox(id=wxID_DIALOG1STATICBOX2,
              label=u'Other players in game', name='staticBox2', parent=self,
              pos=wx.Point(8, 224), size=wx.Size(240, 176), style=0)

        self.listBoxPlayersInGame = wx.ListBox(choices=[],
              id=wxID_DIALOG1LISTBOXPLAYERSINGAME, name=u'listBoxPlayersInGame',
              parent=self, pos=wx.Point(16, 240), size=wx.Size(224, 120),
              style=0)

        self.buttonAttackPlayer = wx.Button(id=wxID_DIALOG1BUTTONATTACKPLAYER,
              label=u'Attack player', name=u'buttonAttackPlayer', parent=self,
              pos=wx.Point(114, 368), size=wx.Size(125, 23), style=0)
        self.buttonAttackPlayer.Bind(wx.EVT_BUTTON,
              self.OnButtonAttackPlayerButton,
              id=wxID_DIALOG1BUTTONATTACKPLAYER)

        self.buttonRefresh = wx.Button(id=wxID_DIALOG1BUTTONREFRESH,
              label=u'Refresh', name=u'buttonRefresh', parent=self,
              pos=wx.Point(9, 403), size=wx.Size(75, 25), style=0)
        self.buttonRefresh.Bind(wx.EVT_BUTTON, self.OnButtonRefreshButton,
              id=wxID_DIALOG1BUTTONREFRESH)

        self.buttonSendMessage = wx.Button(id=wxID_DIALOG1BUTTONSENDMESSAGE,
              label=u'Send Message', name=u'buttonSendMessage', parent=self,
              pos=wx.Point(19, 368), size=wx.Size(88, 23), style=0)
        self.buttonSendMessage.Bind(wx.EVT_BUTTON,
              self.OnButtonSendMessageButton, id=wxID_DIALOG1BUTTONSENDMESSAGE)

        self.buttonSendMessageEnemy = wx.Button(id=wxID_DIALOG1BUTTONSENDMESSAGEENEMY,
              label=u'Send Message', name=u'buttonSendMessageEnemy',
              parent=self, pos=wx.Point(19, 192), size=wx.Size(88, 23),
              style=0)
        self.buttonSendMessageEnemy.Bind(wx.EVT_BUTTON,
              self.OnButtonSendMessageEnemyButton,
              id=wxID_DIALOG1BUTTONSENDMESSAGEENEMY)

    def __init__(self, parent, app ):
        self._init_ctrls(parent)
        self.app = app
        self.OnButtonRefreshButton( None )
        self.SetTitle( self.app.player_name + ': other players' )
        
    def OnButtonRefreshButton(self, event):
        
        enemies = self.app.server_proxy.enum_enemies()
        self.listBoxEnemies.Set( enemies )     
        
        players = self.app.server_proxy.enum_players( self.app.game_name )
        players.remove( self.app.player_name )
        
        for enemy in enemies:
            players.remove( enemy )
            
        self.listBoxPlayersInGame.Set( players )

    def OnButtonSendMessageButton(self, event):
        player_name = self.listBoxPlayersInGame.GetStringSelection() 
        
        if( player_name != '' ):
            self.app.dialog_enter_message.player_name = player_name 
            self.app.dialog_enter_message.ShowModal()

    def OnButtonSendMessageEnemyButton(self, event):
        player_name = self.listBoxEnemies.GetStringSelection() 
        
        if( player_name != '' ):
            self.app.dialog_enter_message.player_name = player_name 
            self.app.dialog_enter_message.ShowModal()
        

    def OnButtonShowPlayerBattlefieldButton(self, event):
        player_name = self.listBoxEnemies.GetStringSelection()
        if( player_name == '' ):
            return
        
        battlefield = self.app.server_proxy.get_enemy_battlefield( player_name )
        
        if( self.app.enemy_battlefields.has_key( player_name ) == False ):
            self.app.enemy_battlefields[ player_name ] = \
                ClientEnemyBattlefieldDlg.create( self.app.main , self.app , player_name )
                
        self.app.enemy_battlefields[ player_name ].Show()
        self.OnButtonRefreshButton(None)
        
    def OnButtonAttackPlayerButton(self, event):
        player_name = self.listBoxPlayersInGame.GetStringSelection()

        if( player_name != '' ):
            self.app.server_proxy.attack_player( player_name )
        self.OnButtonRefreshButton(None)

    def OnDialog1Activate(self, event):
        self.OnButtonRefreshButton(None)

    def OnDialog1InitDialog(self, event):
        self.OnButtonRefreshButton(None)
